﻿using YK.ORM.Attributes;

namespace YK.Console.Core.Entities;

/// <summary>
/// 数据字典子项
/// </summary>
[DataSeederOrder(10)]
public class DataDictItemInfo:AuditableSoftDeleteEntity
{
    /// <summary>
    /// 字典唯一编码
    /// </summary>
    public string Code { get; set; }

    /// <summary>
    /// 字典值(同一编码下唯一)
    /// </summary>
    public string Value { get; set; }

    /// <summary>
    /// 排序号
    /// </summary>
    public int Sort { get; set; }

    /// <summary>
    /// 样式
    /// </summary>
    public string ThemeStyle { get; set; }

    /// <summary>
    /// 描述
    /// </summary>
    public string? Remark { get; set; }

    /// <summary>
    /// 启用状态
    /// </summary>
    public EnabledStatusEnum Enabled { get; set; }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="code"></param>
    /// <param name="value"></param>
    /// <param name="sort"></param>
    /// <param name="themeStyle"></param>
    /// <param name="remark"></param>
    /// <param name="enabled"></param>
    /// <returns></returns>
    public DataDictItemInfo Update(string? code = null, string? value = null, int? sort = null, 
        string? themeStyle = null, string? remark = null, EnabledStatusEnum? enabled = null)
    {
        if (code is not null && Code?.Equals(code) is not true)
            Code = code;
        if(value is not null && Value?.Equals(value) is not true)
            Value = value;
        if (sort.HasValue && Sort != sort)
            Sort = sort.Value;
        if(themeStyle is not null && ThemeStyle?.Equals(themeStyle) is not true)
            ThemeStyle = themeStyle;
        if(remark is not null && Remark?.Equals(remark) is not true)
            Remark = remark;
        if (enabled.HasValue && Enabled != enabled)
            Enabled = enabled.Value;
        return this; 
    }
}
